package com.xunyin.modules.mtorder.service.mapper;


import com.xunyin.common.mapper.CoreMapper;
import com.xunyin.modules.mtorder.domain.MtOrder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 订单表 Mapper 接口
 * <p>
 * Created by xunyinyunshang <3594419785@qq.com>
 * CopyRight 讯音云商 https://www.tonetn.com
 */
@Repository
public interface MtOrderMapper extends CoreMapper<MtOrder> {

    /**
     * 实付充值订单总金额 PAY_AMOUNT
     *
     * @return
     */
    @Select("<script> select IFNULL(sum(pay_amount),0) from mt_order " +
            " where type='recharge'  and STATUS='B' " +
            " <if test =\"storeId !=null\"> and store_id = #{storeId} </if> </script>")
    Double sumRechargeOrderMoney(@Param("storeId") Integer storeId);


    /**
     * 实付卡券订单总金额 PAY_AMOUNT
     *
     * @return
     */
    @Select("<script> select IFNULL(sum(pay_amount),0) from mt_order " +
            " where type in ('hour','numtimes') and STATUS='B' " +
            " <if test =\"storeId !=null\"> and store_id = #{storeId} </if> </script>")
    Double sumCouponOrderMoney(@Param("storeId") Integer storeId);

    /**
     * 充值次数
     *
     * @param storeId
     * @return
     */
    @Select("<script> select count(*) from mt_order " +
            " where type='recharge' " +
            " <if test =\"storeId !=null\"> and store_id = #{storeId} </if> </script>")
    Integer sumRechargeCount(@Param("storeId") Integer storeId);


    BigDecimal getOrderCount();

    BigDecimal getStoreOrderCount(@Param("storeId") Integer storeId);

    BigDecimal getOrderCountByTime(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime);

    BigDecimal getStoreOrderCountByTime(@Param("storeId") Integer storeId, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);

    @Select("select * from mt_order o where o.order_sn = #{orderSn} ")
    MtOrder findByOrderSn(@Param("orderSn") String orderSn);

    BigDecimal getPayMoney();

    BigDecimal getPayMoneyByTime(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime);

    BigDecimal getStorePayMoneyByTime(@Param("storeId") Integer storeId, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);

    BigDecimal getStorePayMoney(@Param("storeId") Integer storeId);

    Integer getPayUserCount();

    Integer getStorePayUserCount(@Param("storeId") Integer storeId);

}
